﻿using System;
using System.Reflection;
using Close2Poco;
using Close2Poco.Tests.TestEntities;
using NUnit.Framework;

namespace Close2Poco.Tests
{
    /// <summary>
    /// Tests our "relationship finder" - which is part of our implementation.  It finds relationships between classes.
    /// </summary>
    [TestFixture]
    public class RelationshipFinderTests
    {
        [Test]
        public void CanFindFromListEnd()
        {
            PropertyInfo listEnd = typeof(Customer).GetProperty("Orders");
            Relationship r = RelationshipFinder.GetRelationship(listEnd);
            Assert.AreSame(typeof(Order).GetProperty("Customer"), r.RefEnd);
        }

        [Test]
        public void CanFindFromRefEnd()
        {
            PropertyInfo refEnd = typeof(Order).GetProperty("Customer");
            Relationship r = RelationshipFinder.GetRelationship(refEnd);
            Assert.AreSame(typeof(Customer).GetProperty("Orders"), r.ListEnd);
        }

        [Test]
        public void CanGetKeyInformationFromRelationship()
        {
            PropertyInfo listEnd = typeof(Customer).GetProperty("Orders");
            Relationship r = RelationshipFinder.GetRelationship(listEnd);
            Assert.AreSame(typeof(Order).GetProperty("CustomerID"), r.KeyAtRefEnd[0]);
            Assert.AreSame(typeof(Customer).GetProperty("CustomerID"), r.KeyAtListEnd[0]);
        }

        [Test, Ignore("Not supported yet")]
        public void CanGetKeyInformationWhenKeyContainsMultipleFields()
        {}

        /// <summary>
        /// We should be able to find relationships where there are multiple relationship between the same pair of classes
        /// </summary>
        [Test, Ignore("Not supported yet")]
        public void CanFindFromListEndWhenMultipleRelationships()
        {}

        /// <summary>
        /// We should be able to find relationships where there are multiple relationship between the same pair of classes
        /// </summary>
        [Test, Ignore("Not supported yet")]
        public void CanFindFromRefEndWhenMulipleRelationships()
        {}

        /// <summary>
        /// We should be able to find relationships when a class refers to itself.  E.g. person.Employees-person.Manager
        /// </summary>
        [Test, Ignore("Test not implemented yet")]
        public void CanFindRelationshipsToSelf()
        {}

    }
}
